<script setup name="WorkFlowApproval">
import { WorkFlowGetLineList,WorkFlowAuthorize } from "@/api/sys/workflow";
import {getCurrentInstance, reactive} from "vue";
const {proxy} = getCurrentInstance();
const {sys_is,hrp_user_sex} = proxy.useDict('sys_is','hrp_user_sex');
let pd = reactive({
  open: false,
  title: "",
  operation: 0,
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    name: null
  },
  rules: {
    enableFlag: [{
      required: true,
      message: "是否不能为空",
      trigger: "change"
    }],
    name: [{
      required: true,
      message: "名称不能为空",
      trigger: "blur"
    }],
    sex: [{
      required: true,
      message: "性别不能为空",
      trigger: "blur"
    }]
  }
});

/** 提交按钮 */
// function submitForm() {
//   proxy.$refs["workflowRef"].validate(valid => {
//     if (valid) {
//       if (pd.operation == 1) {
//         submitFormAdd();
//       } else if (pd.operation == 2) {
//         WorkFlowEdit(pd.form).then(res => {
//           proxy.$modal.msgSuccess("修改成功");
//         });
//       }
//       pd.open = false;
//       emit("ok", pd.operation);
//     }
//   });
// }

/** 提交按钮 */
// function submitFormAdd() {
//   if (pd.form.id > 0) {
//     return
//   }
//   proxy.$refs["workflowRef"].validate(valid => {
//     if (valid) {
//       WorkFlowAdd(pd.form).then(res => {
//         pd.form.id = res.data.id;
//         pdLine.queryParams.id = res.data.id;
//         proxy.$modal.msgSuccess("新增成功");
//       });
//     }
//   });
// }

//approval
function approval(workflow) {
  reset();
  //合并
  pd.form = {...pd.form, ...workflow};
  pd.title = "审批流程";
  pd.open = true;
  pdLine.queryParams.id = pd.form.id;
  getLineList();
}


// 表单重置
function reset() {
  pd.form = {
    id: null,
    name: null,
    sex: null,
    state: "0",
    enableFlag: "0",
    remark: null
  };
  pd.operation = 0;
  pd.title = "";
  lineReset();
  proxy.resetForm("workflowRef");
}



defineExpose({approval});
const emit = defineEmits(["ok"]);

//=========== 定义子表数据 =================
let pdLine = reactive({
  lineList: [],
  open: false,
  loading: true,
  form: {},
  operation: 0,
  queryParams: {
    id: null,
    lineName: null
  },
  rules: {
    enableFlag: [{
      required: true,
      message: "是否不能为空",
      trigger: "change"
    }],
    lineName: [{
      required: true,
      message: "名称不能为空",
      trigger: "blur"
    }]
  }
});
// 表单重置
function lineReset() {
  pdLine.form = {
    id: pd.form.id,
    lineId: null,
    lineName: null,
    orderNum: null,
    state: "0",
    enableFlag: "0",
    remark: null,
    roleName: null
  };
  pdLine.lineList = [];
  pdLine.title = "";
}

function getLineList() {
  pdLine.loading = true;
  WorkFlowGetLineList(pdLine.queryParams).then(res => {
    pdLine.lineList = res.data;
    pdLine.open = false;
    pdLine.loading = false;
    pdLine.operation = 0;
  });
}
function selectRow(selection, row){
  pdLine.form.lineId = row.lineId
}

function authorize(result) {
  WorkFlowAuthorize(pdLine.form.lineId,result).then(res => {
    reset();
    getLineList();
  });
}
</script>
<template>
  <!-- 审批流程对话框 -->
  <el-dialog :title="pd.title" v-model="pd.open" width="1150px" append-to-body>
    <el-form ref="workflowRef" :model="pd.form" :rules="pd.rules" label-width="80px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="名称" prop="name" width="80px">
            <el-input v-model="pd.form.name" placeholder="请输入名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
        </el-col>
        <el-col :span="6">
          <el-form-item label="启用" prop="enableFlag">
            <el-switch v-model="pd.form.enableFlag" active-value="0" inactive-value="1"></el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input v-model="pd.form.remark" type="textarea" placeholder="请输入内容"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table v-loading="pdLine.loading" :data="pdLine.lineList" @select="selectRow">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="名称" align="center" prop="lineName">
        <template #default="scope">
          <el-link type="primary" @click="lineEditOpen(scope.row)" v-hasPermi="['sys:workflow:edit']">
            {{ scope.row.lineName }}
          </el-link>
        </template>
      </el-table-column>
      <!--      <el&#45;&#45;cotablelumn label="启用" align="center" prop="enableFlag">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="sys_state" :value="scope.row.enableFlag"/>-->
      <!--        </template>-->
      <!--      </el&#45;&#45;cotablelumn>-->
      <el-table-column label="备注" align="center" prop="remark"/>
      <el-table-column label="流程顺序" align="center" prop="orderNum"/>
      <!--      <el-table-column label="创建人" align="center" prop="createBy" />-->
      <!--      <el-table-column label="创建时间" align="center" prop="createTime" width="150">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <!--      <el-table-column label="更新时间" align="center" prop="updateTime" width="100">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column fixed="right" label="当前状态" align="center" class-name="small-padding fixed-width" width="300">
        <template #default="scope">
          <el-form-item>
            <el-radio-group v-model="scope.row.result">
              <el-radio label="0">已通过</el-radio>
              <el-radio label="2">待处理</el-radio>
              <el-radio label="1">已拒绝</el-radio>
            </el-radio-group>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column fixed="right" label="操作角色" align="center" prop="roleName" width="200">

      </el-table-column>
    </el-table>

    <el-row class="mb-4">
      <el-col :span="6">
        <el-form-item label="权限提醒：" prop="authority" width="80px">
          <el-button type="primary" @click="authorize(0)">同意</el-button>
          <el-button type="primary" @click="authorize(1)">不同意</el-button>
        </el-form-item>
      </el-col>
    </el-row>
  </el-dialog>

</template>

<style lang='scss' scoped>

</style>